﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.Base;
    using UFIDA.U9.CBO.HR.Department;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFIDA.U9.CBO.SCM.Item;
    using UFIDA.U9.MO.MO;
    using UFSoft.UBF.AopFrame;
    using UFSoft.UBF.Business;
    using UFSoft.UBF.Util.Context;

	/// <summary>
	/// MOSaveSV partial 
	/// </summary>	
	public partial class MOSaveSV 
	{	
		internal BaseStrategy Select()
		{
			return new MOSaveSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class MOSaveSVImpementStrategy : BaseStrategy
	{
		public MOSaveSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			MOSaveSV bpObj = (MOSaveSV)obj;

            //try
            //{
            //    if (bpObj.Data == null || bpObj.Data.Count == 0)
            //        throw new Exception("传入参数为空");
            //    List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

            //    foreach (var dto in bpObj.Data)
            //    {
            //        if (String.IsNullOrEmpty(dto.DocNo))
            //            throw new Exception("必须传入单号[DocNo]");

            //        MO doc = MO.Finder.Find($"DocNo='{dto.DocNo}'");
            //        if (doc == null)
            //        {
            //            //新增逻辑
            //            doc = MOBase.CreateDoc(dto);
            //            //修改单号
            //            EntityUtils.UpdateDocNo<MO>(doc.ID, dto.DocNo);
            //            //审核
            //            doc = MOBase.ApproveDoc(doc);
            //            //返回值
            //            CommonArchiveDataDTOData ret = new CommonArchiveDataDTOData()
            //            {
            //                ID = doc.ID,
            //                Code = doc.DocNo,
            //            };
            //            retlist.Add(ret);
            //        }
            //        else
            //        {
            //            //修改逻辑
            //            throw new AITException(599, $"单号:{dto.DocNo}已经存在!");
            //        }
            //    }

            //    return ResultUtils.success(bpObj, bpObj.Data, retlist);
            //}
            //catch (Exception ex)
            //{
            //    return ResultUtils.error(bpObj, bpObj.Data, ex);
            //}

            return CodeUtils.DocSaveRT(bpObj, bpObj.Data, MOBase.CreateDoc, MOBase.ApproveDoc);
        }
    }

	#endregion
	
	
}